﻿using Unity.Entities;
using UnityEngine;
using ECSData;

/// <summary>
/// 负责处理对应的Entity集合的逻辑和行为
/// </summary>
public class HelloWorldCompomentSystem : ComponentSystem
{
    protected override void OnStartRunning()
    {
        //自动注册并上报实体类
        foreach (var helloworldEntity in GetEntities<HelloWorldEntity>())
        {
            Debug.Log(helloworldEntity.helloWorldComponentData.myUserData.ToString());
            Debug.Log(helloworldEntity.test.str);
        }
    }

    protected override void OnUpdate()
    {
        //所有enitity的deltaTime都是相同的，所以这里可以直接让他们公用相同的deltaTime
        float deltaTime = Time.deltaTime;
        foreach (var helloworldEntity in GetEntities<HelloWorldEntity>())
        {
            helloworldEntity.transform.rotation *= Quaternion.AngleAxis(deltaTime * helloworldEntity.helloWorldComponentData.rotateSpeed, Vector3.up);
        }
    }
}

